﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace UI
{
    public partial class Form1 : Form
    {
         

        public Form1()
        {
            InitializeComponent();
        }
        public void AddSimulationFiles()
        {
            AddSimulationFile(@"C:\Users\adebruij\Dropbox\PnET_Succession\Simulations\Arjan\SIMULATION_sm\output\PNEToutputsites\Site1\Site.csv");
          
        }
        public void AddSimulationFile(string File)
        {
            FileContent c = new FileContent(File);

            string[] years = c.GetUnroundedYears();

            double Xmin = double.MaxValue;
            double Xmax = double.MinValue;

           
            List<double> X = new List<double>();
            for (int i = 1; i < 10000; i++)
            {
                double value =double.Parse(years[i]);
                X.Add(double.Parse(years[i]));
                if (value < Xmin) Xmin = value;
                if (value > Xmax) Xmax = value;
            }

            string[] values = c.GetColumn(7);
            double Ymin = double.MaxValue;
            double Ymax = double.MinValue;

            List<double> Y = new List<double>();
            for (int i = 1; i < 10000; i++)
            {
                double value = double.Parse(values[i]);
                Y.Add(double.Parse(values[i]));
                if (value < Ymin) Ymin = value;
                if (value > Ymax) Ymax = value;
            }

            TabPage tabpage = new TabPage(values[0]);

            tabControl1.Controls.Add(tabpage);

            ZedGraph.ZedGraphControl graph_control = new ZedGraph.ZedGraphControl();



            Action action2 = () => tabpage.Controls.Add(graph_control);
            tabpage.Invoke(action2); // Or use BeginInvoke


            graph_control.GraphPane.XAxis.Scale.Min = Xmin;
            graph_control.GraphPane.XAxis.Scale.Max = Xmax;
            graph_control.GraphPane.XAxis.Scale.MajorStep = (graph_control.GraphPane.XAxis.Scale.Max - graph_control.GraphPane.XAxis.Scale.Min) / 10;
            graph_control.GraphPane.XAxis.Scale.MinorStep = graph_control.GraphPane.XAxis.Scale.MajorStep;

            graph_control.GraphPane.YAxis.Scale.Min = Ymin;
            graph_control.GraphPane.YAxis.Scale.Max = Ymax;
            graph_control.GraphPane.YAxis.Scale.MajorStep = (graph_control.GraphPane.YAxis.Scale.Max - graph_control.GraphPane.YAxis.Scale.Min) / 10;
            graph_control.GraphPane.YAxis.Scale.MinorStep = graph_control.GraphPane.YAxis.Scale.MajorStep;


            graph_control.GraphPane.AddCurve(values[0], X.ToArray(), Y.ToArray(), System.Drawing.Color.Black, ZedGraph.SymbolType.None);

            //tabpage.Controls.Add(graph_control);

            //graph_control.Dock = DockStyle.Fill;

            //graph_control.Show();

        }
      
    }
}
